package org.example.spring_book.config;

import org.example.spring_book.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName ErrorHandler
 * @Description TODO
 * @Author wangxiaodong
 */
@ControllerAdvice
@ResponseBody
public class ErrorHandler {
    @ExceptionHandler
    public Result handler(Exception e){
        return  Result.fail("内部发生错误"+e.getMessage());
    }
    @ExceptionHandler
    public Result handler(NullPointerException e){
        return  Result.fail("内部发生NullPointerException错误");
    }
//    @ExceptionHandler
//    public Result handler(RuntimeException e){
//        return  Result.fail("内部发生RuntimeException错误");
//    }
    @ExceptionHandler
    public Result handler(ArithmeticException e){
        return  Result.fail("内部发生ArithmeticException错误");
    }

}
